package com.itheima.reggie.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.domain.Category;
import com.itheima.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    //新增
    @PostMapping
    public R addCate(@RequestBody Category category){
    categoryService.save(category);
    return R.success(null);
    }

    //菜品分类分页查询
    @GetMapping("/page")
    public R page(int page,int pageSize){
        Page<Category> p = categoryService.findPage(page, pageSize);

        return R.success(p);
    }

    //菜品删除
    @DeleteMapping
    public R delete(Long ids){
        categoryService.deleteById(ids);
       return R.success(null);

    }

    //修改
    @PutMapping
    public R update(@RequestBody Category category){
        categoryService.updateById(category);
        return R.success(null);
    }

    //新增菜品下拉列表
    @GetMapping("/list")
    public R findCuisine(Category category){

        List<Category> categories = categoryService.findCategory(category);

        return R.success(categories);
    }

}
